<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FhDownload;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FhDownloadController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FhDownload(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('b_url')->width(300);
            // $grid->column('type');
            $grid->column('f_url')->width(300);
            $grid->column('show')->switch();
            $grid->column('created_at');
            // $grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FhDownload(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('b_url');
            $show->field('type');
            $show->field('f_url');
            $show->field('show');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FhDownload(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->radio('type')->options([1=>"百度云链接",2=>"本地上传资源"])->when(1,function(Form $form){
                $form->text('b_url');
            })->when(2,function(Form $form){
                $form->file('f_url')->maxSize(150*1024);
            })->default(1);
            $form->switch('show')->default(1);
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
